package cn.dengyongsheng;

import java.util.Scanner;

public class Main {
    // 自定义的a1到a5
    static float a1 = -10, a2 = -1, a3 = 0, a4 = 1, a5 = 10;

    public static float fun(float r) throws ParameterRIsTooSmall {
        if (a1 > r && a2 > r && a3 > r && a4 > r && a5 > r) {
            throw new ParameterRIsTooSmall();
        }
        // 找到最大值
        float[] a_val = {a1, a2, a3, a4, a5};
        // max的初始值为负无穷
        float a_max = Float.NEGATIVE_INFINITY;
        for (float a : a_val) {
            if (a <= r && a > a_max) {
                a_max = a;
            }
        }
        return r - a_max;
    }

    public static void main(String[] args) throws ParameterRIsTooSmall {
        Scanner in = new Scanner(System.in);
        System.out.print("请输入实数r：");
        float input_r = in.nextFloat();
        System.out.println("函数执行结果为：" + fun(input_r));
    }
}
